﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using POSSystem.BLL;

namespace WebUI.EditPages
{
    public partial class PaymentHistViewer : BasePage
    {
        int custID = 0;
        protected void Page_Load(object sender, EventArgs e)
        {
            base.Page_Load(sender, e);

            if(Request.QueryString[CUSTID] != "")
            {
                custID = int.Parse(Request.QueryString[CUSTID]);
            }

            if (!IsPostBack)
            {
                LoadInvoice();
            }
        }

        public void btnSearch_OnClick(object sender, EventArgs e)
        {
            View_PaymentHist ivc = null;
            if (custID > 0)
            {
                ivc = View_PaymentHist.GetPaymentsByCustID(custID, txtSearch.Text);
            }
            ivc.Sort = View_PaymentHist.ColumnNames.PaidDate + " desc";
            paymentList.SourceObject = ivc;
            paymentList.Refresh();
        }

        void LoadInvoice()
        {
            View_PaymentHist ivc = null;
            if (custID > 0)
            {
                ivc = View_PaymentHist.GetPaymentsByCustID(custID);
                ivc.Sort = View_PaymentHist.ColumnNames.PaidDate + " desc";
                paymentList.SourceObject = ivc;
                paymentList.Refresh();
            }
        }
    }
}
